//
//  HHTaskConstant.swift
//  testTaskQueue
//
//  Created by kingdee on 2021/2/7.
//

import Foundation

@objc protocol HHTaskManagerDelegate: NSObjectProtocol {
    
    @objc optional func clearResource()
    @objc optional func startService()
    @objc optional func creatTask(_ task: @escaping TaskBlock, overRetry: TaskBlock?, retryMaxCount: Int, retryTimeStrategy: [Int], mustSuccess: Bool, retryAtOnce: Bool) -> String
    @objc optional func addTaskToRun(taskIdentifier: String)
    @objc optional func cancelTask(taskIdentifier: String)
    @objc optional func cancelAllTask()
}

func synchronized<T>(_ lock: AnyObject, _ closure: () throws -> T) rethrows -> T {
    objc_sync_enter(lock)
    defer { objc_sync_exit(lock) }
    return try closure()
}

typealias TaskBlock = (@escaping (Bool)->Void) -> Void
typealias TaskEndBlock = (@escaping ()->Void) -> Void
